package library.and.xps.com.step.view.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import io.realm.RealmList;
import library.and.xps.com.step.R;
import library.and.xps.com.step.m.model.Team;
import library.and.xps.com.step.m.model.User;
import library.and.xps.com.step.util.CommonUtils;
import library.and.xps.com.step.view.base.BaseActivity;

public class TeamDetailActivity extends BaseActivity {
    ImageView iv_team_detail_avatar, iv_back;
    TextView tv_team_detail_teamName, tv_tv_team_detail_teamId, tv_team_detail_org_desc, actionbar_title, tv_tv_team_detail_org_address;
    Team team;

    @Override
    protected int getLayout() {
        return R.layout.activity_team_detail;
    }

    @Override
    protected void setData() {
        team = getCurrentTeam();
        tv_team_detail_teamName.setText("团队名称:" + team.getTname());
        tv_team_detail_org_desc.setText("公司简介:" + "\n" + team.getDescription());
        tv_tv_team_detail_teamId.setText("团队ID:" + team.getTId());
        tv_tv_team_detail_org_address.setText("公司地址:" + team.getAddress());

        CommonUtils.setUpimg(this,iv_team_detail_avatar,team.getMarker(),true);

    }

    /*
   * 获取当前已加入的team
   * */
    Team getCurrentTeam() {
        User user = getUser();
        RealmList<Team> team = user.getTeams();
        if (team != null && team.size() > 0) {
            return team.get(team.size() - 1);
        }
        return null;
    }

    @Override
    protected void init() {
        iv_team_detail_avatar = r2v(R.id.iv_team_detail_avatar);
        tv_team_detail_teamName = r2v(R.id.tv_team_detail_teamName);
        tv_tv_team_detail_teamId = r2v(R.id.tv_tv_team_detail_teamId);
        tv_team_detail_org_desc = r2v(R.id.tv_team_detail_org_desc);
        actionbar_title = r2v(R.id.actionbar_tv_title);
        tv_tv_team_detail_org_address = r2v(R.id.tv_tv_team_detail_org_address);
        iv_back = r2v(R.id.actionbar_iv_back);

        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        actionbar_title.setText("企业详情");

    }
}
